<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page contentType="text/html;charset=utf-8" language="java" %>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <%@ include file="/assets/public.jsp"%>
    <title>添加文章</title>

</head>
<body>
<%@include file="/assets/header.jsp"%>

<div class="d-flex align-items-stretch">
    <!-- Sidebar Navigation-->
    <%@ include file="/assets/side.jsp"%>
    <!-- Sidebar Navigation end-->
    <div class="page-content">
        <div class="page-header">
            <div class="container-fluid">
                <h2 class="h5 no-margin-bottom">添加文章</h2>
            </div>
        </div>

        <section class="no-padding-bottom">

            <div class="block-body">
                <div class="form-group">
                    <label class="form-control-label">标题</label>
                    <input id="title" type="text" placeholder="文章标题" class="form-control">
                </div>
                <div class="form-group">
                    <label class="form-control-label">文章内容</label>
                    <textarea id="content" class="form-control" rows="5"></textarea>
                </div>
                <div class="text-center form-group">
                    <input id="addArt" type="submit" value="发布" class="btn btn-primary">
                    <input id="path" type="hidden" value="${pageContext.request.contextPath}" />
                </div>
            </div>

        </section>

        <%@include file="/assets/footer.jsp"%>
    </div>
</div>
</body>
<script>
    $(function () {
        $("#addArt").click(function () {
            var path = $("#path").val();
            $.ajax({
                url:path+"/article/add",
                type:"post",
                data:{
                    title:$("#title").val(),
                    content:$("#content").val()
                },
                success:function (data) {
                    if (data === "0"){
                        alert("发布成功");
                        location.href = path + "/article/findArticles";
                    }
                    else {
                        alert("发布失败");
                    }
                }
            })
        })
    });

</script>
</html>